/**
 * Created by BIYY on 2018-6-20.
 */
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
const smp = new SpeedMeasurePlugin();
const path = require('path');
const os = require('os');
const webpack = require('webpack');
const loadersConfig = require('./loaders/index');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { project, version } = require('../build/project');
function resolve(dir) {
	return path.join(__dirname, '..', dir);
}
let webpackConfig = {
	entry: {
		index: [
			//主入口
			'babel-polyfill',
			'./src/projects/' + project + '/main.js'
		]
	},
	resolve: {
		extensions: [ '.ts', '.tsx', '.web.js', '.js', '.jsx', '.json', '.less', '.css' ],
		modules: [
			resolve('../node_modules'),
			resolve('../node_modules/react-router/node_modules'),
			resolve('../src')
		],
		alias: {
			'@': resolve('../src'),
			src: resolve('../src'),
			assets: resolve('../src/assets'),
			components: resolve('../src/components')
		}
	},
	module: {
		rules: loadersConfig
	},
	optimization: {
		runtimeChunk: {
			name: 'manifest'
		},
		splitChunks: {
			cacheGroups: {
				commons: {
					test: /[\\/]node_modules[\\/]/,
					name: 'vendor',
					chunks: 'all'
				}
			}
		}
	},
	plugins: [
		new HtmlWebpackPlugin({
			filename: 'index.html',
			template: 'src/projects/' + project + '/index.html',
			inject: true,
		}),
		new MiniCssExtractPlugin({
			filename: 'static/css/[name]-.css?ver=' ,
			chunkFilename: 'static/css/[name]-.css?ver='
		}),
		
	]
};
module.exports = smp.wrap(webpackConfig)
